package Service;

import java.util.ArrayList;
import java.util.List;
import dao.ProjectDao;
import pojo.PageBean;
import pojo.Project;

public class ProjectService {
	ProjectDao cdao;
	public PageBean<Project> show(int currentPage,int pageSize,String uid) {
		cdao = new ProjectDao();
		PageBean<Project> pb = new PageBean<Project>();
		pb.setList(cdao.showProjectByType(currentPage, pageSize, uid));
		pb.setTotal(cdao.getTotal(uid));
		int totalPage=(cdao.getTotal(uid)%pageSize==0)?(cdao.getTotal(uid)/pageSize):(cdao.getTotal(uid)/pageSize+1);
		pb.setTotalPage(totalPage);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		return pb;
	}
//	public List<Project> showProjectByType(int currentPage,int pageSize,String id){
//		cdao = new ProjectDao();
//		List<Project>list=new ArrayList<Project>();
//		list=cdao.showProjectByType(currentPage, pageSize, id);
//		return list;
//	}
	public int add(Project p) {
		cdao=new ProjectDao();
		int flag=cdao.add(p);
		return flag;
	}
	public int update(Project p) {
		cdao=new ProjectDao();
		int flag=cdao.update(p);
		return flag;
	}
	public Project getProject(String id) {
		cdao=new ProjectDao();
		Project p =cdao.getOneProject(id);
		return p;
	}
	public int delProject(String id) {
		int flag=0;
		cdao=new ProjectDao();
		flag=cdao.del(id);
		return flag;
	}
}

